package user;
import book.BookList;
import operate.*;
import java.util.Scanner;
public class NormalUser extends User {
    /**
     * @param name
     * 负责人：段佳豪
     * 把对书的操作功能都写进集合里
     * 并保证父类里的放法doOperate（）能顺利进行
     * 0.退出程序
     * 1.展示书籍
     * 2.查找书籍
     * 3.借书
     * 4.还书
     * 5.收藏
     * 6.点赞
     * */
    public NormalUser(String name) {
        super(name);
        this.iOperates = new IOperate[]{
            new Exit(),// 0
            new Display(), // 1
            new Find(),// 2
            new Borrow(),//3
            new Return(),// 4
            new State(),// 5
            new Love() //6
        };
    }
    /**
     * 负责人：段佳豪
     * 打印管理者所看到的菜单
     * 让管理者选择进行什么操作
     * 并把操作返回
     */
    public void menu(User user,BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        //打印选项
        while (true) {
            System.out.println("------------图书馆------------");
            printNormaluser();
            System.out.println("请输入选择：");
            int choice ;
            while(true) {
                if (scanner.hasNextInt()) {
                    choice = scanner.nextInt();
                    break;
                } else {
                    System.out.println("非法输入,请重新输入:");
                    scanner.next();
                }
            }
            switch (choice)
            {
                case 1:
                    user.doOperate(user,1,bookList);
                    break;
                case 2:
                    user.doOperate(user,2,bookList);
                    break;
                case 3:
                    user.doOperate(user,3,bookList);
                    break;
                case 4:
                    user.doOperate(user,4,bookList);
                    break;
                case 5:
                    user.doOperate(user,5,bookList);
                    break;
                case 6:
                    user.doOperate(user,6,bookList);
                    break;
                case 0:
                    user.doOperate(user,0,bookList);
                    return;
            }
        }
    }
    private void printNormaluser() {
        System.out.println("1.展示书籍");
        System.out.println("2.查找书籍");
        System.out.println("3.借书");
        System.out.println("4.还书");
        System.out.println("5.收藏");
        System.out.println("6.点赞");
        System.out.println("0.返回主菜单");
    }
}
